package com.example.clientapp;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.drawerlayout.widget.DrawerLayout;

import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.widget.LinearLayout;

public class MainActivity extends AppCompatActivity {
    private DrawerLayout drawerLayout;
    private LinearLayout linearLayout;
    private static final String TAG = "MainActivity";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        drawerLayout = this.findViewById(R.id.drawer_menu);
        linearLayout = this.findViewById(R.id.linearlayout);
        //点击事件
        findViewById(R.id.open_drawer).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                drawerLayout.openDrawer(Gravity.LEFT);
            }
        });

        //关闭事件
        findViewById(R.id.close_drawer).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                drawerLayout.closeDrawer(Gravity.LEFT);
            }
        });
        //侧滑监听
        drawerLayout.addDrawerListener(new DrawerLayout.DrawerListener() {
            @Override
            public void onDrawerSlide(@NonNull View drawerView, float slideOffset) {
                //设置拉出布局的宽度
                linearLayout.setX(slideOffset * drawerView.getWidth());

                Log.e(TAG, "onDrawerSlide: " + "滑动时执行");
                Log.e(TAG, "onDrawerSlide偏移量: " + slideOffset);
                Log.e(TAG, "onDrawerSlide偏移的宽度: " + drawerView.getWidth());
            }

            @Override
            public void onDrawerOpened(@NonNull View drawerView) {
                Log.e(TAG, "onDrawerSlide: " + "完全展开时执行");
            }

            @Override
            public void onDrawerClosed(@NonNull View drawerView) {
                Log.e(TAG, "onDrawerSlide: " + "完全关闭时执行");
            }

            @Override
            public void onDrawerStateChanged(int newState) {
                Log.e(TAG, "onDrawerSlide: " + "改变状态时时执行");
            }
        });
    }
}
